package com.joysw.ui.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.joysw.R;
import com.joysw.models.GoodsModel;
import com.nostra13.universalimageloader.core.ImageLoader;
/**   
 * @Title: DtqListAdapter.java 
 * @Package com.joysw.ui.adapter 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author LIMINGYAN  
 * @date 2015年3月29日 下午3:28:13 
 * @version V1.0   
 */
public class ShopGridViewAdapter extends BaseAdapter {

    private ArrayList<GoodsModel> data;
    private Context context=null;
    private LayoutInflater inflater=null;
    public ShopGridViewAdapter(Context context,ArrayList<GoodsModel> data) {
        super();
        this.data = data;
        this.context = context;
        
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if(convertView==null){
            
            
            convertView=inflater.inflate(R.layout.shop_gridview_item, null);
            holder=new Holder();
            holder.goods_info=(TextView) convertView.findViewById(R.id.goods_introduce);
            holder.goods_pic=(ImageView) convertView.findViewById(R.id.gridview_img);
            holder.goods_price=(TextView) convertView.findViewById(R.id.goods_price);
            
            convertView.setTag(holder);
            
        }else{
            holder=(Holder) convertView.getTag();
            
        }
        holder.goods_info.setText(data.get(position).getGoods_info());
        ImageLoader.getInstance().displayImage(data.get(position).getImage_url(), holder.goods_pic);
        return convertView;
    }
    private class Holder{
        
        TextView goods_info;
        ImageView goods_pic;
        TextView goods_price;
	}
}
